home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / cblas / test_dot.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-18  |  9.0 KB  |  384 lines

  1. #include <gsl/gsl_test.h>
  2. #include <gsl/gsl_ieee_utils.h>
  3. #include <gsl/gsl_math.h>
  4. #include <gsl/gsl_cblas.h>
  5.  
  6. #include "tests.h"
  7.  
  8. void
  9. test_dot (void) {
  10. const double flteps = 1e-4, dbleps = 1e-6;
  11.   {
  12.    int N = 1;
  13.    float alpha = 0.0f;
  14.    float X[] = { 0.733f };
  15.    float Y[] = { 0.825f };
  16.    int incX = 1;
  17.    int incY = -1;
  18.    float expected = 0.604725f;
  19.    float f;
  20.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  21.    gsl_test_rel(f, expected, flteps, "sdsdot(case 1)");
  22.   };
  23.  
  24.  
  25.   {
  26.    int N = 1;
  27.    float alpha = 0.1f;
  28.    float X[] = { 0.733f };
  29.    float Y[] = { 0.825f };
  30.    int incX = 1;
  31.    int incY = -1;
  32.    float expected = 0.704725f;
  33.    float f;
  34.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  35.    gsl_test_rel(f, expected, flteps, "sdsdot(case 2)");
  36.   };
  37.  
  38.  
  39.   {
  40.    int N = 1;
  41.    float alpha = 1.0f;
  42.    float X[] = { 0.733f };
  43.    float Y[] = { 0.825f };
  44.    int incX = 1;
  45.    int incY = -1;
  46.    float expected = 1.604725f;
  47.    float f;
  48.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  49.    gsl_test_rel(f, expected, flteps, "sdsdot(case 3)");
  50.   };
  51.  
  52.  
  53.   {
  54.    int N = 1;
  55.    float alpha = 0.0f;
  56.    float X[] = { -0.812f };
  57.    float Y[] = { -0.667f };
  58.    int incX = -1;
  59.    int incY = 1;
  60.    float expected = 0.541604f;
  61.    float f;
  62.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  63.    gsl_test_rel(f, expected, flteps, "sdsdot(case 4)");
  64.   };
  65.  
  66.  
  67.   {
  68.    int N = 1;
  69.    float alpha = 0.1f;
  70.    float X[] = { -0.812f };
  71.    float Y[] = { -0.667f };
  72.    int incX = -1;
  73.    int incY = 1;
  74.    float expected = 0.641604f;
  75.    float f;
  76.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  77.    gsl_test_rel(f, expected, flteps, "sdsdot(case 5)");
  78.   };
  79.  
  80.  
  81.   {
  82.    int N = 1;
  83.    float alpha = 1.0f;
  84.    float X[] = { -0.812f };
  85.    float Y[] = { -0.667f };
  86.    int incX = -1;
  87.    int incY = 1;
  88.    float expected = 1.541604f;
  89.    float f;
  90.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  91.    gsl_test_rel(f, expected, flteps, "sdsdot(case 6)");
  92.   };
  93.  
  94.  
  95.   {
  96.    int N = 1;
  97.    float alpha = 0.0f;
  98.    float X[] = { 0.481f };
  99.    float Y[] = { 0.523f };
  100.    int incX = -1;
  101.    int incY = -1;
  102.    float expected = 0.251563f;
  103.    float f;
  104.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  105.    gsl_test_rel(f, expected, flteps, "sdsdot(case 7)");
  106.   };
  107.  
  108.  
  109.   {
  110.    int N = 1;
  111.    float alpha = 0.1f;
  112.    float X[] = { 0.481f };
  113.    float Y[] = { 0.523f };
  114.    int incX = -1;
  115.    int incY = -1;
  116.    float expected = 0.351563f;
  117.    float f;
  118.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  119.    gsl_test_rel(f, expected, flteps, "sdsdot(case 8)");
  120.   };
  121.  
  122.  
  123.   {
  124.    int N = 1;
  125.    float alpha = 1.0f;
  126.    float X[] = { 0.481f };
  127.    float Y[] = { 0.523f };
  128.    int incX = -1;
  129.    int incY = -1;
  130.    float expected = 1.251563f;
  131.    float f;
  132.    f = cblas_sdsdot (N, alpha, X, incX, Y, incY);
  133.    gsl_test_rel(f, expected, flteps, "sdsdot(case 9)");
  134.   };
  135.  
  136.  
  137.   {
  138.    int N = 1;
  139.    float X[] = { 0.785f };
  140.    float Y[] = { -0.7f };
  141.    int incX = 1;
  142.    int incY = -1;
  143.    float expected = -0.5495f;
  144.    float f;
  145.    f = cblas_sdot(N, X, incX, Y, incY);
  146.    gsl_test_rel(f, expected, flteps, "sdot(case 10)");
  147.   };
  148.  
  149.  
  150.   {
  151.    int N = 1;
  152.    double X[] = { 0.79 };
  153.    double Y[] = { -0.679 };
  154.    int incX = 1;
  155.    int incY = -1;
  156.    double expected = -0.53641;
  157.    double f;
  158.    f = cblas_ddot(N, X, incX, Y, incY);
  159.    gsl_test_rel(f, expected, dbleps, "ddot(case 11)");
  160.   };
  161.  
  162.  
  163.   {
  164.    int N = 1;
  165.    float X[] = { 0.474f, -0.27f };
  166.    float Y[] = { -0.144f, -0.392f };
  167.    int incX = 1;
  168.    int incY = -1;
  169.    float expected[2] = {-0.174096f, -0.146928f};
  170.    float f[2];
  171.    cblas_cdotu_sub(N, X, incX, Y, incY, &f);
  172.    gsl_test_rel(f[0], expected[0], flteps, "cdotu(case 12) real");
  173.    gsl_test_rel(f[1], expected[1], flteps, "cdotu(case 12) imag");
  174.   };
  175.  
  176.  
  177.   {
  178.    int N = 1;
  179.    float X[] = { 0.474f, -0.27f };
  180.    float Y[] = { -0.144f, -0.392f };
  181.    int incX = 1;
  182.    int incY = -1;
  183.    float expected[2] = {0.037584f, -0.224688f};
  184.    float f[2];
  185.    cblas_cdotc_sub(N, X, incX, Y, incY, &f);
  186.    gsl_test_rel(f[0], expected[0], flteps, "cdotc(case 13) real");
  187.    gsl_test_rel(f[1], expected[1], flteps, "cdotc(case 13) imag");
  188.   };
  189.  
  190.  
  191.   {
  192.    int N = 1;
  193.    double X[] = { -0.87, -0.631 };
  194.    double Y[] = { -0.7, -0.224 };
  195.    int incX = 1;
  196.    int incY = -1;
  197.    double expected[2] = {0.467656, 0.63658};
  198.    double f[2];
  199.    cblas_zdotu_sub(N, X, incX, Y, incY, &f);
  200.    gsl_test_rel(f[0], expected[0], dbleps, "zdotu(case 14) real");
  201.    gsl_test_rel(f[1], expected[1], dbleps, "zdotu(case 14) imag");
  202.   };
  203.  
  204.  
  205.   {
  206.    int N = 1;
  207.    double X[] = { -0.87, -0.631 };
  208.    double Y[] = { -0.7, -0.224 };
  209.    int incX = 1;
  210.    int incY = -1;
  211.    double expected[2] = {0.750344, -0.24682};
  212.    double f[2];
  213.    cblas_zdotc_sub(N, X, incX, Y, incY, &f);
  214.    gsl_test_rel(f[0], expected[0], dbleps, "zdotc(case 15) real");
  215.    gsl_test_rel(f[1], expected[1], dbleps, "zdotc(case 15) imag");
  216.   };
  217.  
  218.  
  219.   {
  220.    int N = 1;
  221.    float X[] = { -0.457f };
  222.    float Y[] = { 0.839f };
  223.    int incX = -1;
  224.    int incY = 1;
  225.    float expected = -0.383423f;
  226.    float f;
  227.    f = cblas_sdot(N, X, incX, Y, incY);
  228.    gsl_test_rel(f, expected, flteps, "sdot(case 16)");
  229.   };
  230.  
  231.  
  232.   {
  233.    int N = 1;
  234.    double X[] = { 0.949 };
  235.    double Y[] = { -0.873 };
  236.    int incX = -1;
  237.    int incY = 1;
  238.    double expected = -0.828477;
  239.    double f;
  240.    f = cblas_ddot(N, X, incX, Y, incY);
  241.    gsl_test_rel(f, expected, dbleps, "ddot(case 17)");
  242.   };
  243.  
  244.  
  245.   {
  246.    int N = 1;
  247.    float X[] = { 0.852f, -0.045f };
  248.    float Y[] = { 0.626f, -0.164f };
  249.    int incX = -1;
  250.    int incY = 1;
  251.    float expected[2] = {0.525972f, -0.167898f};
  252.    float f[2];
  253.    cblas_cdotu_sub(N, X, incX, Y, incY, &f);
  254.    gsl_test_rel(f[0], expected[0], flteps, "cdotu(case 18) real");
  255.    gsl_test_rel(f[1], expected[1], flteps, "cdotu(case 18) imag");
  256.   };
  257.  
  258.  
  259.   {
  260.    int N = 1;
  261.    float X[] = { 0.852f, -0.045f };
  262.    float Y[] = { 0.626f, -0.164f };
  263.    int incX = -1;
  264.    int incY = 1;
  265.    float expected[2] = {0.540732f, -0.111558f};
  266.    float f[2];
  267.    cblas_cdotc_sub(N, X, incX, Y, incY, &f);
  268.    gsl_test_rel(f[0], expected[0], flteps, "cdotc(case 19) real");
  269.    gsl_test_rel(f[1], expected[1], flteps, "cdotc(case 19) imag");
  270.   };
  271.  
  272.  
  273.   {
  274.    int N = 1;
  275.    double X[] = { -0.786, -0.341 };
  276.    double Y[] = { -0.271, -0.896 };
  277.    int incX = -1;
  278.    int incY = 1;
  279.    double expected[2] = {-0.09253, 0.796667};
  280.    double f[2];
  281.    cblas_zdotu_sub(N, X, incX, Y, incY, &f);
  282.    gsl_test_rel(f[0], expected[0], dbleps, "zdotu(case 20) real");
  283.    gsl_test_rel(f[1], expected[1], dbleps, "zdotu(case 20) imag");
  284.   };
  285.  
  286.  
  287.   {
  288.    int N = 1;
  289.    double X[] = { -0.786, -0.341 };
  290.    double Y[] = { -0.271, -0.896 };
  291.    int incX = -1;
  292.    int incY = 1;
  293.    double expected[2] = {0.518542, 0.611845};
  294.    double f[2];
  295.    cblas_zdotc_sub(N, X, incX, Y, incY, &f);
  296.    gsl_test_rel(f[0], expected[0], dbleps, "zdotc(case 21) real");
  297.    gsl_test_rel(f[1], expected[1], dbleps, "zdotc(case 21) imag");
  298.   };
  299.  
  300.  
  301.   {
  302.    int N = 1;
  303.    float X[] = { -0.088f };
  304.    float Y[] = { -0.165f };
  305.    int incX = -1;
  306.    int incY = -1;
  307.    float expected = 0.01452f;
  308.    float f;
  309.    f = cblas_sdot(N, X, incX, Y, incY);
  310.    gsl_test_rel(f, expected, flteps, "sdot(case 22)");
  311.   };
  312.  
  313.  
  314.   {
  315.    int N = 1;
  316.    double X[] = { -0.434 };
  317.    double Y[] = { -0.402 };
  318.    int incX = -1;
  319.    int incY = -1;
  320.    double expected = 0.174468;
  321.    double f;
  322.    f = cblas_ddot(N, X, incX, Y, incY);
  323.    gsl_test_rel(f, expected, dbleps, "ddot(case 23)");
  324.   };
  325.  
  326.  
  327.   {
  328.    int N = 1;
  329.    float X[] = { -0.347f, 0.899f };
  330.    float Y[] = { -0.113f, -0.858f };
  331.    int incX = -1;
  332.    int incY = -1;
  333.    float expected[2] = {0.810553f, 0.196139f};
  334.    float f[2];
  335.    cblas_cdotu_sub(N, X, incX, Y, incY, &f);
  336.    gsl_test_rel(f[0], expected[0], flteps, "cdotu(case 24) real");
  337.    gsl_test_rel(f[1], expected[1], flteps, "cdotu(case 24) imag");
  338.   };
  339.  
  340.  
  341.   {
  342.    int N = 1;
  343.    float X[] = { -0.347f, 0.899f };
  344.    float Y[] = { -0.113f, -0.858f };
  345.    int incX = -1;
  346.    int incY = -1;
  347.    float expected[2] = {-0.732131f, 0.399313f};
  348.    float f[2];
  349.    cblas_cdotc_sub(N, X, incX, Y, incY, &f);
  350.    gsl_test_rel(f[0], expected[0], flteps, "cdotc(case 25) real");
  351.    gsl_test_rel(f[1], expected[1], flteps, "cdotc(case 25) imag");
  352.   };
  353.  
  354.  
  355.   {
  356.    int N = 1;
  357.    double X[] = { -0.897, -0.204 };
  358.    double Y[] = { -0.759, 0.557 };
  359.    int incX = -1;
  360.    int incY = -1;
  361.    double expected[2] = {0.794451, -0.344793};
  362.    double f[2];
  363.    cblas_zdotu_sub(N, X, incX, Y, incY, &f);
  364.    gsl_test_rel(f[0], expected[0], dbleps, "zdotu(case 26) real");
  365.    gsl_test_rel(f[1], expected[1], dbleps, "zdotu(case 26) imag");
  366.   };
  367.  
  368.  
  369.   {
  370.    int N = 1;
  371.    double X[] = { -0.897, -0.204 };
  372.    double Y[] = { -0.759, 0.557 };
  373.    int incX = -1;
  374.    int incY = -1;
  375.    double expected[2] = {0.567195, -0.654465};
  376.    double f[2];
  377.    cblas_zdotc_sub(N, X, incX, Y, incY, &f);
  378.    gsl_test_rel(f[0], expected[0], dbleps, "zdotc(case 27) real");
  379.    gsl_test_rel(f[1], expected[1], dbleps, "zdotc(case 27) imag");
  380.   };
  381.  
  382.  
  383. }
  384.